# Temperature converter
import string #necessary to convert f_or_c's value to lowercase

def tempConverter(): #Define a function named tempConverter
    print "Temperature Converter\n" #Welcome statement

    temp = None #Assign None to a variable named temp
    while not temp: #While temp is invalid, try to take input from the user and convert it
        try:        # to an integer value. If not an integer, catch the exception and try again.
            temp = int(raw_input("Enter a temperature: "))
        except ValueError:
            print "Not a valid integer!"

    #Assign the string 'f' or 'c' to the variable f_or_c to determine whether
    # the user wants to convert their temperature to Fahrenheit or Celsius.
    f_or_c = string.lower(raw_input("Convert to (F)ahrenheit or (C)elsius? "))

    #If the user typed c, convert the temperature to Celsius.
    if f_or_c == "c":
        newtemp = (5.0/9.0) * (temp - 32.0)
        print temp, "degrees Fahrenheit is equal to", newtemp, "degrees Celsius."
    #If f, convert to Fahrenheit.
    elif f_or_c == "f":
        newtemp = (9.0/5.0) * temp + 32.0
        print temp, "degrees Celsius is equal to", newtemp, "degrees Fahrenheit."
    #If the user typed something else, restart the program.
    else:
        print "Not a valid option.\n"
        tempConverter()

#Call the function tempConverter to begin the program.        
tempConverter()
